# -*-coding:UTF-8 -*-
from __future__ import division

#
indexlist = []
scorelist = []
score = 0


# 计算指标得分
# def getScore(tmpValue):
#     global score
#     score = 0.5
#     if tmpValue < indexlist[0]:
#         score = scorelist[0]
#     elif tmpValue > indexlist[-1]:
#         score = scorelist[-1]
#     else:
#         for i in range(indexlist):
#             if tmpValue > indexlist[i] and tmpValue <= indexlist[i+1]:
#                 score = scorelist[i+1]
#
#     return score

# 年度用户电量同比增长率
def yearGrowthRate(lastMonth, lastYearLastMonth):
    global indexlist, scorelist, score

    if lastYearLastMonth == 0:
        return score
    growthRate = lastMonth / lastYearLastMonth - 1
    return growthRate


# 用电量连续两年增长情况
def twoYearsOfGrowth(lastMonth, lastYearLastMonth, theYearBeforeLastMonth):
    score = 0
    if theYearBeforeLastMonth == 0 or lastYearLastMonth == 0 or lastMonth == 0:
        return score
    rate1 = (lastMonth - lastYearLastMonth) / lastYearLastMonth
    rate2 = (lastYearLastMonth - theYearBeforeLastMonth) / theYearBeforeLastMonth
    return rate1 / rate2 - 1


# 欠款
def debt(debtlist, receivablelist):
    allDebtRate = 0
    for i in range(len(debtlist)):
        if receivablelist[i] == 0 or debtlist[i] == 0:
            tmpRate = 1
        else:
            tmpRate = debtlist[i] / receivablelist[i]
        allDebtRate = tmpRate + allDebtRate
    averageRate = allDebtRate / 12
    return averageRate


# 违约金比率
def breakContractMoney(breakContractlist, receivablelist):
    print "breakContractlist"
    print breakContractlist
    print "receivablelist"
    print receivablelist
    allDebtRate = 0
    for i in range(len(breakContractlist)):
        print i
        if receivablelist[i] == 0 or breakContractlist[i] == 0:
            tmpRate = 1
        else:
            tmpRate = breakContractlist[i] / receivablelist[i]
        allDebtRate = tmpRate + allDebtRate
    averageRate = allDebtRate / 12
    return averageRate


# 违约金频率
def breakContractRatio(intervalList):
    payDayAverage = sum(intervalList) / len(intervalList)
    sdsq = sum([(i - payDayAverage) ** 2 for i in intervalList])
    stdev = (sdsq / len(intervalList)) ** .5
    tmpRate = stdev / payDayAverage
    return tmpRate


# 是否停电
def powerdown():
    pass


# 缴费频率的稳定性
def payfrequency(intervalList):
    payDayAverage = sum(intervalList) / len(intervalList)
    print sum(intervalList) / len(intervalList)
    sdsq = sum([(i - payDayAverage) ** 2 for i in intervalList])
    stdev = (sdsq / len(intervalList)) ** .5
    tmpRate = stdev / payDayAverage
    return tmpRate


# 违约金回收率
def breakContractFrequency(realbreakContractlist, receivablelist):
    if sum(receivablelist) != 0:
        rate = sum(realbreakContractlist) / sum(receivablelist)
    else:
        rate = 0
    return rate


# 电费回收率
def eleCostsfrequency(realeleCostslist, shouldreceivedlist):
    rate = sum(realeleCostslist) / sum(shouldreceivedlist)
    return rate


# 用户余额充足率
def overageAdequateRate(overage, shouldreceivedMoney):
    if overage == 0 or shouldreceivedMoney == 0:
        return 0

    overageRate = overage / shouldreceivedMoney

    return overageRate


if __name__ == '__main__':
    pass
